#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
typedef pair<int, int> pi;
pi a[N * 2];
int n, h, b, mx[N], mi[N], cnt, ans;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i].first, a[i].second = i;
  sort(a + 1, a + n + 1, [](pi &a, pi &b) {
    if (a.first == b.first)
      return a.second < b.second;
    else
      return a.first < b.first;
  });
  for (int i = 1; i <= n; ++i) {
    if (i == 1 || a[i].first != a[i - 1].first) {
      mx[cnt] = a[i - 1].second;
      mi[++cnt] = a[i].second;
    }
  }
  mx[cnt] = a[n].second;
  b = true;  // 下降
  h = 1 << 30;
  for (int i = 1; i <= cnt; ++i) {
    if (b) {
      // 下降
      if (h < mi[i])
        h = mx[i];
      else
        h = mi[i], b = false, ans++;
    } else {
      // 上升
      if (h > mx[i])
        h = mi[i];
      else
        h = mx[i], b = true;
    }
  }
  cout << ans << endl;
}
